<?php
namespace Admin\Controller;
use Think\Controller;

class AdminController extends CommonController{
	public function index(){
		$admins = D('Admin')->getAdmins();
		$this->assign('admins',$admins);
		$this->display('');
	}
	public function add(){
		$this->display();
	}
	public function del(){
		$adminid = $_GET['adminid'];
		
		$obj = D('Admin')->delete($adminid);
		if($obj !== false)
		{
			$this->success("成功删除id号为{$adminid}的记录！",'',2);
		}else{
			$this->error('删除失败！','',2);
		}
	}
	public function addcheck(){
		$adminusr = $_POST['adminusr'];
		$adminpwd = $_POST['adminpwd'];
		
		// print_r($rst);exit;
		// if($rst == true)
		// {
		// 	$this->error('该用户已存在!','',2);
		// }
		if($adminusr != '' && $adminpwd != ''){
			$data['adminUsr'] = $adminusr;
			$data['adminPwd'] = md5($adminpwd);
			$obj = M('admin');
			$obj -> add($data);

			$this->success('用户名为'.$adminusr.'的用户增加成功！','index',3);
		}else if($adminusr == ''){
			$this->error('用户名为空！','',2);
		}else if($adminpwd == ''){
			$this->error('密码为空！','',2);
		}
		
	}
	public function setStatus(){
		$adminid = $_POST['adminid'];
		$adminstatus = $_POST['adminstatus'];
		
		
		echo $adminstatus;
	}
	public function ajax_statu(){
        	$model = M('admin');
			if($model->save($_POST)){
				echo "1";
			}else{
				echo "0";
			}
    }
    public function edit(){
    	$adminid = $_GET['adminid'];
    	$obj = D('admin')->where('adminId="'.$adminid.'"')->find();
    
    	// print_r($adminpwd);
    	// print_r($obj);exit;
    	$adminusr = $obj['adminusr'];
    	$adminpwd = md5($obj['adminpwd']);
    	$this->assign('adminusr',$adminusr);
    	$this->assign('adminpwd',$adminpwd);
		$this->display();
    }
    public function editcheck(){
    	$adminusr = $_POST['$adminusr'];
    	$adminpwd = $_POST['$adminpwd'];
    	$adminpwd = $_POST['$adminpwds'];
    }
}